package com.youlin;

import org.apache.activemq.ScheduledMessage;
import org.springframework.jms.core.MessagePostProcessor;

import javax.jms.JMSException;
import javax.jms.Message;

public class DelayMessagePostProcessor implements MessagePostProcessor {

    private Long delay;

    public DelayMessagePostProcessor(Long delay) {
        this.delay = delay;
    }

    @Override
    public Message postProcessMessage(Message message) throws JMSException {
        if (delay != null && delay > 0L)
            message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
        return message;
    }

}
